home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / SDKs / ScreenLight™ 1.0.1 / CodeExamples / BitsOLight 68k-style / blModule.c < prev   
Encoding:
C/C++ Source or Header  |  1996-01-04  |  8.6 KB  |  357 lines  |  [TEXT/MPS ]

  1. /**********************************************************************************
  2.   ExampleModule.c
  3.  
  4.  
  5.         DOCUMENTATION
  6.  
  7.                 an example module for ScreenLight 
  8.                 using 68k style globals.
  9.  
  10.  
  11.         MODULE CODE RESOURCES
  12.  
  13.             Here are the types we define for the kinds of Modules one
  14.         might produce.
  15.         
  16.             App: creator='SS-ß'
  17.  
  18.             68k Only: type='SS-m'
  19.                         code='SS-m' 0
  20.  
  21.             PPC Only: type='SS-p', 
  22.                         std cfrg
  23.  
  24.             Fat Binary: type='SS-f', 
  25.                         std cfrg
  26.                         code='SS-m' 0
  27.  
  28.  
  29.  
  30.         HISTORY
  31.  
  32.                 03jun94 bh          New Today
  33.  
  34.                 19jun94    bh            Clean up Close code        
  35.                                     added monitor profile code
  36.                                     added test for Preview Mode
  37.  
  38.                 21aug94 bh            CheckRequiredFeatures() added
  39.                 27aug94 bh            util CalcHSBtoRGB()
  40.                 28nov95 bh            new module interface
  41.  
  42.  
  43.  
  44.         Copyright )WORK-IN_PROGRESS  Noesis Software Construction
  45. **********************************************************************************/
  46.  
  47. #include "fp.h"
  48.  
  49. //*********************************************************************************
  50. //                                                                  I N C L U D E                                                                             I N C L U D E S 
  51.  
  52. #include "ModuleRoutines.h"
  53.  
  54.  
  55. //*********************************************************************************
  56. //                                                                  F O R W A R D                                                                                        G L O B A L S
  57.  
  58. OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr);
  59.  
  60.  
  61.  
  62. //*********************************************************************************
  63. //                                                                                                                      C O N S T A N T S
  64.  
  65.         // use this struct for all of your 
  66.         // private data needs !
  67.  
  68. struct SampleData {
  69.        long        useColor;
  70.        long        whichColor;
  71.        long        lightCnt;
  72. };
  73. typedef struct SampleData SampleData;
  74. typedef SampleData *SampleDataPtr;
  75.  
  76.  
  77. //*********************************************************************************
  78. //      main - MPW Linker wanted a routine named main.
  79. //*********************************************************************************
  80. OSErr main( ModuleParamBlkPtr mpPtr)
  81. {
  82.     return ModOpen( mpPtr);
  83. }
  84.  
  85. //*********************************************************************************
  86. //      ModOpen
  87. //*********************************************************************************
  88. OSErr ModOpen( ModuleParamBlkPtr mpPtr)
  89. {
  90.     OSErr                err = noErr;
  91.     SampleDataPtr        sData;
  92.     short                refNum;
  93.  
  94.     //Debugger();
  95.     if ( (err=InitmProcs(mpPtr)) != noErr)
  96.         return err;
  97.     
  98.     // If you have your own About proc defined, use the following line
  99.     mpPtr->mProcs.aboutProc = NewModAboutProc( ABOUTPROCNAME);
  100.  
  101.     // Check for Features Required...
  102.     if (  (err=CheckRequiredFeatures()) != noErr)
  103.         goto error;
  104.  
  105.     
  106.     // Test for preview, 
  107.     if ( mpPtr->mInPreview) {
  108.         ;
  109.     }
  110.  
  111.     // Allocate our private storage
  112.     sData = (SampleDataPtr)NewPtrClear(sizeof(SampleData));
  113.     if (err = MemError()) goto error;
  114.  
  115.     // Set other local variables
  116.     sData->useColor = 0;
  117.     sData->lightCnt = 0;
  118.  
  119.     // Get into our file
  120.     //  the Module is the current Resource File during the Open()
  121.     //  call, so any and all custom resources are available...
  122.     //
  123.     //resH = Get1Resource( 'tClr', 128);
  124.  
  125.     // store private data in paramBlk
  126.     mpPtr->mStorage = (long)sData;
  127.         
  128.     // done
  129.     return noErr;
  130.  
  131. error:
  132.     if ( sData) {
  133.         DisposPtr((Ptr)sData);
  134.     }
  135.  
  136.     mpPtr->mStorage = 0;
  137.         
  138.     return err;
  139. }
  140.  
  141.  
  142. //*********************************************************************************
  143. //    ModDraw
  144. //
  145. //  The Port is set for you on entry. Have fun !
  146. //
  147. //*********************************************************************************
  148. #define kMaxPts    100
  149.  
  150. OSErr ModDraw( ModuleParamBlkPtr mpPtr)
  151. {
  152.     SampleDataPtr sData;
  153.     short cnt, numLights;
  154.     Point    pts[ kMaxPts];
  155.  
  156.     if ( IRandom(1,4) == 4)
  157.         return noErr;
  158.  
  159.     sData = (SampleDataPtr)mpPtr->mStorage;
  160.     numLights = sData->lightCnt;
  161.  
  162.     for ( cnt=0; cnt<numLights; cnt++) {
  163.         pts[cnt].h = IRandom( 0, mpPtr->mGraf->portRect.right);
  164.         pts[cnt].v = IRandom( 0, mpPtr->mGraf->portRect.bottom);
  165.     }
  166.  
  167.     if ( sData->useColor == 0)
  168.         ForeColor( whiteColor);
  169.     else
  170.         ForeColor( sData->whichColor);
  171.  
  172.     for ( cnt=0; cnt<numLights; cnt++) {
  173.         //MoveTo( pts[cnt].h, pts[cnt].v);
  174.         //Line( 0, 0);
  175.         MoveTo( pts[cnt].h-1, pts[cnt].v);
  176.         Line( 0, 0);
  177.         MoveTo( pts[cnt].h+1, pts[cnt].v);
  178.         Line( 0, 0);
  179.         MoveTo( pts[cnt].h, pts[cnt].v-1);
  180.         Line( 0, 0);
  181.         MoveTo( pts[cnt].h, pts[cnt].v+1);
  182.         Line( 0, 0);
  183.     }
  184.  
  185.     ForeColor( blackColor);
  186.     for ( cnt=0; cnt<numLights; cnt++) {
  187.         //MoveTo( pts[cnt].h, pts[cnt].v);
  188.         //Line( 0, 0);
  189.         MoveTo( pts[cnt].h-1, pts[cnt].v);
  190.         Line( 0, 0);
  191.         MoveTo( pts[cnt].h+1, pts[cnt].v);
  192.         Line( 0, 0);
  193.         MoveTo( pts[cnt].h, pts[cnt].v-1);
  194.         Line( 0, 0);
  195.         MoveTo( pts[cnt].h, pts[cnt].v+1);
  196.         Line( 0, 0);
  197.     }
  198.  
  199.     return noErr;
  200. }
  201.  
  202.  
  203. //*********************************************************************************
  204. //    ModClose
  205. //
  206. //        Clean-up after Module Run. Dispose of any storage on the heap. 
  207. //    The resource file and Control values are updated automatically. 
  208. //
  209. //*********************************************************************************
  210. OSErr ModClose( ModuleParamBlkPtr mpPtr)
  211. {
  212.     SampleDataPtr        data = (SampleDataPtr)mpPtr->mStorage;
  213.     OSErr    err            = noErr;
  214.     
  215.     if (data != 0) {
  216.         DisposePtr((Ptr)data);
  217.         err = MemError();
  218.     }
  219.  
  220.     return err;
  221. }
  222.  
  223.  
  224.  
  225. //*************************************************
  226. //    Sample About Procedure for a Module
  227.  
  228. OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr)
  229. {
  230.     Rect            tmpR;
  231.     EventRecord        evt;
  232.     SampleDataPtr    data;
  233.     
  234.     data = (SampleDataPtr)mpPtr->mStorage;
  235.     
  236.     // GrafPort is set on entry
  237.     tmpR = mpPtr->mGraf->portRect;
  238.     EraseRect( &tmpR);
  239.     
  240.     if ( GetPortPixDepth( mpPtr->mGraf) > 1)
  241.         ForeColor( redColor);
  242.      else 
  243.          ForeColor( whiteColor);
  244.     PaintRect( &tmpR);
  245.     
  246.     while ( !WaitNextEvent( mDownMask+keyDownMask, &evt, GetCaretTime(), 0))    
  247.         ; 
  248.         
  249.     ForeColor( blackColor);
  250.     PaintRect( &tmpR);
  251.     
  252.     return;
  253. }
  254.  
  255.  
  256. //*************************************************
  257. OSErr ModChangePrefs( ModuleParamBlkPtr mpPtr)
  258. {
  259.     SampleDataPtr sData;
  260.     long    **tIDh;
  261.     short    val;
  262.     OSErr    err = noErr;
  263.  
  264.     // We get passed in a ptr to the ModControlRecord in 
  265.     //  the mInfo fld. Our only clue to which control type
  266.     //  this is is by the first long in every ModControlRec,
  267.     //  the User-Defined ID number ! 
  268.  
  269.     sData = (SampleDataPtr)mpPtr->mStorage;
  270.     tIDh = (long**)mpPtr->mInfo;
  271.  
  272.     switch (**tIDh) {
  273.         case 1:                            // Slider
  274.             {
  275.                 ScSLD_SliderRec **tScSLD_RecH;
  276.                 // we have a horizSlider
  277.         
  278.                 tScSLD_RecH = (ScSLD_SliderRec **)mpPtr->mInfo;
  279.                 sData->lightCnt = (*tScSLD_RecH)->curValue;
  280.         
  281.             }
  282.             break;
  283.     
  284.         case 2:                            // Check Box
  285.             {
  286.                 ScCHK_CheckBoxRec **tScCHK_RecH;
  287.                 // we have a check box
  288.                 // This CheckBox turns color use on and off
  289.                 
  290.                 // Test to see if we want color allowed
  291.                 if ( !IsColorPort( mpPtr->mGraf) 
  292.                     || GetPortPixDepth( mpPtr->mGraf) < 4)
  293.                         return kModDisableControl;
  294.                 
  295.                 tScCHK_RecH = (ScCHK_CheckBoxRec **)mpPtr->mInfo;
  296.                 sData->useColor = (*tScCHK_RecH)->val;
  297.         
  298.             }
  299.             break;
  300.     
  301.         case 3:                            // Popup/List
  302.             {
  303.                 ScLST_ListRec    **tScLST_RecH;
  304.                 // we have a popup, set value based on hard-wired 
  305.                 //  association with MENU resource in Module Controls.
  306.                 // This Popup chooses a drawing color
  307.     
  308.                 // Test to see if we want color allowed
  309.                 if ( !IsColorPort( mpPtr->mGraf) 
  310.                     || GetPortPixDepth( mpPtr->mGraf) < 4)
  311.                         return kModDisableControl;
  312.                 
  313.                 tScLST_RecH = (ScLST_ListRec **)mpPtr->mInfo;
  314.                 switch ( (*tScLST_RecH)->curValue) {
  315.                     case 1:    sData->whichColor = cyanColor; break;
  316.                     case 2:    sData->whichColor = yellowColor; break;
  317.                     case 3:    sData->whichColor = magentaColor; break;
  318.                     case 4:    sData->whichColor = whiteColor; break;
  319.                     default: break;
  320.                 };
  321.                 
  322.             }
  323.             break;
  324.     
  325.         case 4:                            // Button
  326.             {
  327.                 ScBTN_ButtonRec **tScBTN_RecH;
  328.                 // we have a button
  329.                 //  this btn msg will be called by the App when init'ing
  330.                 //  ctls, just to check if we want the button disabled or not.
  331.                 //  Check the 'isHit' field to see if you have a real btn hit.
  332.         
  333.                 tScBTN_RecH = (ScBTN_ButtonRec **)mpPtr->mInfo;
  334.     
  335.                 if ( (*tScBTN_RecH)->isHit) {
  336.                     // NOTE: if you want explicit or implicit globals 
  337.                     //   like a string literal in double-quotes, on 
  338.                     //   the 68k side, you must add the A4() macros 
  339.                     //   ie "\pButton Title ="
  340.                 
  341.                     ParamText( 0, (*tScBTN_RecH)->titleStr,0,0);
  342.                     CautionAlert( 128, 0);
  343.                 }
  344.             }
  345.             break;
  346.     
  347.         };
  348.  
  349.     return noErr;
  350. }
  351.  
  352.  
  353.  
  354.  
  355. //**********************************************************************************
  356. //                                                      E N D   O F   L I S T I N G  
  357.